home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_6_6.arc / 66L1.ASM next >
Assembly Source File  |  1988-08-17  |  3KB  |  135 lines

  1. ;
  2. ; *** Listing 1 ***
  3. ;
  4. ; Program to put up a mode 10h EGA graphics screen, then save it
  5. ; to the file SNAPSHOT.SCR.
  6. ;
  7. VGA_SEGMENT    equ    0a000h
  8. GC_INDEX    equ    3ceh    ;Graphics Controller Index register
  9. READ_MAP    equ    4    ;Read Map register index in GC
  10. DISPLAYED_SCREEN_SIZE equ (640/8)*350
  11.                 ;# of displayed bytes per plane in a
  12.                 ; hi-res graphics screen
  13. ;
  14. stack    segment para stack 'STACK'
  15.     db    512 dup (?)
  16. stack    ends
  17. ;
  18. Data    segment    word 'DATA'
  19. SampleText db    'This is bit-mapped text, drawn in hi-res '
  20.     db    'EGA graphics mode 10h.', 0dh, 0ah, 0ah
  21.     db    'Saving the screen (including this text)...'
  22.     db    0dh, 0ah, '$'
  23. Filename db    'SNAPSHOT.SCR',0    ;name of file we're saving to
  24. ErrMsg1    db    '*** Couldn''t open SNAPSHOT.SCR ***',0dh,0ah,'$'
  25. ErrMsg2    db    '*** Error writing to SNAPSHOT.SCR ***',0dh,0ah,'$'
  26. WaitKeyMsg db    0dh, 0ah, 'Done. Press any key to end...',0dh,0ah,'$'
  27. Handle    dw    ?    ;handle of file we're saving to
  28. Plane    db    ?    ;plane being read
  29. Data    ends
  30. ;
  31. Code    segment
  32.     assume    cs:Code, ds:Data
  33. Start    proc    near
  34.     mov    ax,Data
  35.     mov    ds,ax
  36. ;
  37. ; Go to hi-res graphics mode.
  38. ;
  39.     mov    ax,10h    ;AH = 0 means mode set, AL = 10h selects
  40.             ; hi-res graphics mode
  41.     int    10h    ;BIOS video interrupt
  42. ;
  43. ; Put up some text, so the screen isn't empty.
  44. ;
  45.     mov    ah,9    ;DOS print string function
  46.     mov    dx,offset SampleText
  47.     int    21h
  48. ;
  49. ; Delete SNAPSHOT.SCR if it exists.
  50. ;
  51.     mov    ah,41h    ;DOS unlink file function
  52.     mov    dx,offset Filename
  53.     int    21h
  54. ;
  55. ; Create the file SNAPSHOT.SCR.
  56. ;
  57.     mov    ah,3ch    ;DOS create file function
  58.     mov    dx,offset Filename
  59.     sub    cx,cx        ;make it a normal file
  60.     int    21h
  61.     mov    [Handle],ax    ;save the handle
  62.     jnc    SaveTheScreen    ;we're ready to save if no error
  63.     mov    ah,9        ;DOS print string function
  64.     mov    dx,offset ErrMsg1
  65.     int    21h        ;notify of the error
  66.     jmp    short Done    ;and done
  67. ;
  68. ; Loop through the 4 planes, making each readable in turn and
  69. ; writing it to disk. Note that all 4 planes are readable at
  70. ; A000:0000; the Read Map register selects which plane is readable
  71. ; at any one time.
  72. ;
  73. SaveTheScreen:
  74.     mov    [Plane],0    ;start with plane 0
  75. SaveLoop:
  76.     mov    dx,GC_INDEX
  77.     mov    al,READ_MAP    ;set GC Index to Read Map register
  78.     out    dx,al
  79.     inc    dx
  80.     mov    al,[Plane]    ;get the # of the plane we want
  81.                 ; to save
  82.     out    dx,al    ;set to read from the desired plane
  83.     mov    ah,40h    ;DOS write to file function
  84.     mov    bx,[Handle]
  85.     mov    cx,DISPLAYED_SCREEN_SIZE ;# of bytes to save
  86.     sub    dx,dx    ;write all displayed bytes at A000:0000
  87.     push    ds
  88.     mov    si,VGA_SEGMENT
  89.     mov    ds,si
  90.     int    21h    ;write the displayed portion of this plane
  91.     pop    ds
  92.     cmp    ax,DISPLAYED_SCREEN_SIZE ;did all bytes get written?
  93.     jz    SaveLoopBottom
  94.     mov    ah,9        ;DOS print string function
  95.     mov    dx,offset ErrMsg2
  96.     int    21h        ;notify about the error
  97.     jmp    short DoClose    ;and done
  98. SaveLoopBottom:
  99.     mov    al,[Plane]
  100.     inc    ax    ;point to the next plane
  101.     mov    [Plane],al
  102.     cmp    al,3    ;have we done all planes?
  103.     jbe    SaveLoop ;no, so do the next plane
  104. ;
  105. ; Close SNAPSHOT.SCR.
  106. ;
  107. DoClose:
  108.     mov    ah,3eh    ;DOS close file function
  109.     mov    bx,[Handle]
  110.     int    21h
  111. ;
  112. ; Wait for a keypress.
  113. ;
  114.     mov    ah,9    ;DOS print string function
  115.     mov    dx,offset WaitKeyMsg
  116.     int    21h    ;prompt
  117.     mov    ah,8    ;DOS input without echo function
  118.     int    21h
  119. ;
  120. ; Restore text mode.
  121. ;
  122.     mov    ax,3
  123.     int    10h
  124. ;
  125. ; Done.
  126. ;
  127. Done:
  128.     mov    ah,4ch    ;DOS terminate function
  129.     int    21h
  130. Start    endp
  131. Code    ends
  132.     end    Start
  133.  
  134.  
  135.